﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

public class FinishController : MonoBehaviour {

    private void OnTriggerEnter(Collider other)
    {
        if (_isFinished)
        {
            return;
        }
        if (other.CompareTag("Player"))
        {
            //玩家胜利.
            //other.GetComponent<PlayerCharacter>().SetCanMoveState(false);
            other.GetComponent<PlayerCharacter>().SetTriggerState(true);
            other.GetComponent<PlayerCharacter>().ChangeGravityState(false);
            Debug.Log("胜利");
            GameManager.Instance.FinishGame();
            StartCoroutine(FixPlayerPos(other.transform));
            //CameraView.Instance.Rotating();
        }
    }

    private bool _isFinished = false;

    /// <summary>
    /// 固定玩家的位置.
    /// </summary>
    private IEnumerator FixPlayerPos(Transform player)
    {
        //Destroy(player.GetComponent<PlayerCharacter>());
        //原来的触发器取消.
        _isFinished = true;
        player.DOMove(new Vector3(-1.5f, 22, 10), 1f);
        player.GetComponent<PlayerCharacter>().ShowLight();
        yield return new WaitForSeconds(1);
        CameraView.Instance.Rotating();
    }
}
